package com.huifaapp.mall.activity;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huifaapp.mall.R;

public class AftersaleActivity extends AppCompatActivity {


    private Button btOnlyrefunds,btBarter,btRefundofrefunds,btService;
    //换货原因
    private TextView tvReturing;
    //货物状态
    private TextView tvStatusofgoods;
    //退款原因
    private TextView tvReasons;
    private LinearLayout llBigrefund,llSmallrefund;
    //WENTIMIAOSHU
    private TextView tvProblem;
    private EditText edMsproblem;
    private EditText edFunds;
    private View inflate;
    private Dialog dialog;
    private ImageView iv_allorder_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_aftersale);

        initView();
        initLinster();
    }


    private void initView() {
        btOnlyrefunds = (Button) findViewById(R.id.activity_aftersale_onlyrefunds);
        btBarter = (Button) findViewById(R.id.activity_aftersale_barter);
        btRefundofrefunds = (Button) findViewById(R.id.activity_aftersale_refundofrefunds);
        btService = (Button) findViewById(R.id.activity_aftersale_service);
        //huowuzhuangtai
        tvStatusofgoods = (TextView) findViewById(R.id.activity_aftersale_statusofgoods);
        tvReasons = (TextView) findViewById(R.id.activity_aftersale_reasons);
        llBigrefund = (LinearLayout) findViewById(R.id.activity_aftersale_bigrefund);
        llSmallrefund = (LinearLayout) findViewById(R.id.activity_aftersale_smallrefund);
        tvReturing = (TextView) findViewById(R.id.activity_aftersale_returing);
        tvProblem = (TextView) findViewById(R.id.activity_aftersale_problem);
        edMsproblem = (EditText) findViewById(R.id.activity_aftersale_msproblem);
        edFunds = (EditText) findViewById(R.id.activity_aftersale_refunds);
        iv_allorder_back= (ImageView) findViewById(R.id.iv_allorder_back);
        iv_allorder_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    private void initLinster() {
        btOnlyrefunds.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tvStatusofgoods.setVisibility(view.VISIBLE);
                tvReasons.setVisibility(view.VISIBLE);
                llBigrefund.setVisibility(view.VISIBLE);
                llSmallrefund.setVisibility(view.VISIBLE);
                edFunds.setVisibility(view.VISIBLE);
                edMsproblem.setVisibility(view.GONE);
                tvProblem.setVisibility(view.GONE);
                tvReturing.setVisibility(view.GONE);
                tvStatusofgoods.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        statusofgoods();

                    }
                });




            }
        });
        btBarter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tvReturing.setVisibility(view.VISIBLE);
                tvStatusofgoods.setVisibility(view.GONE);
                tvReasons.setVisibility(view.GONE);
                llBigrefund.setVisibility(view.GONE);
                llSmallrefund.setVisibility(view.GONE);
                tvProblem.setVisibility(view.GONE);
                edFunds.setVisibility(view.VISIBLE);
                edMsproblem.setVisibility(view.GONE);
                tvProblem.setVisibility(view.GONE);
            }
        });
        btRefundofrefunds.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tvReasons.setVisibility(view.VISIBLE);
                llBigrefund.setVisibility(view.VISIBLE);
                tvReturing.setVisibility(view.GONE);
                tvStatusofgoods.setVisibility(view.GONE);
                llSmallrefund.setVisibility(view.GONE);
                tvProblem.setVisibility(view.GONE);
                edFunds.setVisibility(view.VISIBLE);
                edMsproblem.setVisibility(view.GONE);
            }
        });
        btService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tvReasons.setVisibility(View.VISIBLE);
                tvProblem.setVisibility(View.VISIBLE);
                edMsproblem.setVisibility(View.VISIBLE);
                edFunds.setVisibility(View.GONE);
                llBigrefund.setVisibility(view.GONE);
                tvReturing.setVisibility(view.GONE);
                tvStatusofgoods.setVisibility(view.GONE);
                llSmallrefund.setVisibility(view.GONE);
            }
        });

    }

    private void statusofgoods() {
        dialog = new Dialog(AftersaleActivity.this,R.style.ActionSheetDialogStyle);
        //填充对话框的布局
        inflate = LayoutInflater.from(AftersaleActivity.this).inflate(R.layout.dialog_statusofgoods, null);
        //将布局设置给Dialog
        dialog.setContentView(inflate);
        //获取当前Activity所在的窗体
        Window dialogWindow = dialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity( Gravity.BOTTOM);
        WindowManager windowManager = getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.y = 20;//设置Dialog距离底部的距离
        lp.width = display.getWidth();
        dialog.getWindow().setAttributes(lp);
//       将属性设置给窗体
        dialogWindow.setAttributes(lp);
        dialog.show();//显示对话框
    }


}